<template>
	<view>
		<my-search @click="goToSearch"></my-search>
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="true">
			<swiper-item v-for="(item,index) in swiperList" :key="index">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>

		<!-- 导航栏 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item, index) in navList" :key="index" @click="clickNavItem(item)">
				<image :src="item.image_src"></image>
			</view>
		</view>

		<!-- 楼层列表 -->
		<view class="floor-list">
			<view class="floor-item" v-for="(item, index) in floorList" :key="index">
				<image :src="item.floor_title.image_src"></image>

				<view class="floor-item-box">
					<navigator class="item-left-box" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src"
							:style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
					</navigator>

					<view class="item-right-box">
						<navigator class="item-right-box-img" v-for="(item2, index2) in item.product_list" :key="index2"
							v-if="index2 !== 0" :url="item2.url">
							<image :src="item2.image_src" :style="{width:item2.image_width + 'rpx'}" mode="widthFix">
							</image>
						</navigator>
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import badgeMixins from '@/mixins/tabbar-badge.js'

	export default {
		mixins:[badgeMixins],
		data() {
			return {
				swiperList: [],
				navList: [],
				floorList: []
			};
		},

		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getfloorList()
		},

		methods: {
			// 请求数据
			async getSwiperList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/swiperdata')
				// console.log(res)
				// 请求失败
				if (res.meta.status !== 200) return uni.$showmsg()
				// 请求成功
				this.swiperList = res.message
			},
			async getNavList() {
				// 请求数据
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/catitems')
				// 请求时失败
				if (res.meta.status !== 200) return uni.$showmsg()
				// 请求成功
				this.navList = res.message
			},
			clickNavItem(item) {
				if (item.name === '分类') {
					uni.switchTab({
						url: '/pages/category/category'
					})
				}
			},
			async getfloorList() {
				// 请求数据
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/floordata')
				console.log(res)
				if (res.meta.status !== 200) return uni.$showmsg()

				res.message.forEach(mes => {
					mes.product_list.forEach(pro => {
						pro.url = `/subpkg/goods_list/goods_list?${pro.navigator_url.split('?')[1]}`
					})
				})
				// 请求成功
				this.floorList = res.message
			},
			goToSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
	// 轮播图
	swiper {
		height: 330rpx;

		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}

	// 导航栏
	.nav-list {
		display: flex;
		flex-wrap: nowrap;
		justify-content: space-around;
		margin: 15rpx 0;

		.nav-item image {
			width: 128rpx;
			height: 140rpx;
		}
	}

	// 楼层列表
	.floor-item image {
		width: 100%;
		height: 60rpx;
	}

	.floor-item-box {
		display: flex;
		padding-left: 15rpx;

		.item-right-box {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;
		}
	}
</style>
